﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LynxWiki.DomainModel
{
    public class AttSearchData
    {
        public string ID { get; set; } /* ID includes TopicName and WikiDir in the index */
        public string AttachmentName { get; set; }
        public string AttachmentDir { get; set; }
        public string NameSpace { get; set; }
        public string Creator { get; set; }
        public DateTime CreatedOn { get; set; }
        public string AttachmentText { get; set; }
        public string Tags { get; set; }  /* each tag is space separated */
        public string Type { get; set; }

        public AttSearchData() { }

        public AttSearchData(AttachmentVersion av)
        {
            ID = av.Namespace + ":" + av.AttachmentName;
            AttachmentName = av.AttachmentName;
            AttachmentDir = av.AttachmentDir;
            Creator = av.Creator;
            CreatedOn = av.CreatedOn;
            if (av.AttachmentText != null) {
                AttachmentText = av.AttachmentText;
            }
            else {
                AttachmentText = string.Empty;
            }
            NameSpace = av.Namespace;

            string tempTags = string.Empty;
            if (av.Tags != null) {
                foreach (string t in av.Tags) {
                    if (!string.IsNullOrEmpty(tempTags)) tempTags += " ";
                    tempTags += t;
                }
            }
            Tags = tempTags;

            Type = av.FileType;
        }
    }
}
